﻿using System;
using System.Collections.Generic;
using System.Text;
using A2Z.BusinessObjects;
using KYO.DAL;
using ObjectPersistence;
using BusinessLayerHelper;
namespace A2Z.BusinessService
{
   
    public class InforService
    {
        InformationAssembler informationAssembler = new InformationAssembler();
        CommentAssembler commentAssembler = new CommentAssembler();
        public List<NewInforShort> GetNewInforShortList(int topNumber)
        {
            List<NewInforShort> listNewInforShort = new List<NewInforShort>();
            PersistentList<Information> listInformation = GetTopInformations(topNumber);

            foreach(Information information in listInformation)
            {
                NewInforShort inforShort = new NewInforShort();

                inforShort.TitleShort = information.Title;
                inforShort.InforId = information.InformationID;

                inforShort.ImageUrl = information.ImageUrl;
                inforShort.ContentShort = information.Abstract;
                listNewInforShort.Add(inforShort);
            }
            return listNewInforShort;
        }
        public PersistentList<Comment> GetAllCommentByInforId(int inforId,string sortExpression)
        {
            string where = "InformationId = "+inforId+ " ORDER BY DateCreate "+ sortExpression ;
           
            return commentAssembler.ReadCollection(where);
        }

        public PersistentList<Information> GetAllInformations(string sortExpression)
        {
            return informationAssembler.ReadCollectionAll("InformationID "+sortExpression);
        }
        public PersistentList<Information> GetTopInformations(int topNumber)
        {
            string where = "(InformationID IN (SELECT TOP ("+topNumber+") InformationID FROM Information))";
            return informationAssembler.ReadCollection(where);
        }
    }

   
}
